package com.zhyl.demo.service.impl;

import com.zhyl.demo.entity.Medication;
import com.zhyl.demo.mapper.MedicationMapper;
import com.zhyl.demo.service.MedicationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * @author yang3
 */
@Service
public class MedicationServiceImpl implements MedicationService {
    private final MedicationMapper medicationMapper;

    @Autowired
    private MedicationServiceImpl(MedicationMapper medicationMapper){
        this.medicationMapper = medicationMapper;
    }

    @Override
    public ArrayList<Medication> getMedicList() {
        ArrayList<Medication> medicList = medicationMapper.getMedicList();
        if (medicList!=null){
            return medicList;
        }else {
            return null;
        }
    }

    @Override
    public ArrayList<Medication> getSelectMedic(String medicName) {
        ArrayList selectMedic = medicationMapper.getSelectMedic(medicName);
        if (selectMedic!=null){
            return selectMedic;
        }else {
            return null;
        }
    }

    @Override
    public Boolean updateMedic(Medication medication) {
        int i = medicationMapper.updateMedic(medication);
        return i > 0;
    }

    @Override
    public Boolean createMedic(Medication medication) {
        int i = medicationMapper.createMedic(medication);
        return i > 0;
    }

    @Override
    public Boolean deleteMedic(Integer medId) {
        int i = medicationMapper.deleteMedic(medId);
        return i > 0;
    }

    @Override
    public Medication checkMedic(String name) {
        Medication checkMedic = medicationMapper.checkMedic(name);
        if (checkMedic!=null){
            return checkMedic;
        }else {
            return null;
        }
    }
}
